package cn.rdq.iknessplatform.controller;

import cn.rdq.api.po.Catelog;
import cn.rdq.api.vo.CatelogCollectedVo;
import cn.rdq.common.CommonResult;
import cn.rdq.iknessplatform.service.CatelogCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/catelog-collected")
public class CatelogCollectedController {

    @Autowired
    private CatelogCollectService collectService;

    @PostMapping("/user")
    public CommonResult userCollected(@RequestBody CatelogCollectedVo catelogCollectedVo) {
        List<Catelog> catelogs = collectService.listInfoByUserId(catelogCollectedVo);
        return CommonResult.success().pageSuccess(catelogs);
    }

    @PostMapping("/state")
    public CommonResult collectState(@RequestBody CatelogCollectedVo catelogCollectedVo) {
        return CommonResult.successObj(collectService.getCollected(catelogCollectedVo));
    }

    @PostMapping("/collect")
    public CommonResult collect(@RequestBody CatelogCollectedVo catelogCollectedVo) {
        boolean collect = collectService.collect(catelogCollectedVo);
        return CommonResult.successObj(collect);
    }

    @PostMapping("/delete")
    public CommonResult deleteCollected(@RequestBody CatelogCollectedVo catelogCollectedVo) {
        boolean cancelCollect = collectService.cancelCollect(catelogCollectedVo);
        return CommonResult.successObj(cancelCollect);
    }

}
